package com.zj.guava.eventbus;

import com.google.common.eventbus.EventBus;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EventBusExample {
    private static final Logger logger = LoggerFactory.getLogger(EventBusExample.class);


    @Test
    public void testSimpleEvent() {
        EventBus bus = new EventBus(((throwable, subscriberExceptionContext) -> {
//            logger.info(subscriberExceptionContext.getEvent().toString());
//            logger.info(subscriberExceptionContext.getEventBus().toString());
//            logger.info(subscriberExceptionContext.getSubscriber().toString());
//            logger.info(subscriberExceptionContext.getSubscriberMethod().toString());
            logger.error(throwable.getMessage());

        }));
        bus.register(new SimpleListener());
        logger.info("bus start!");
        bus.post("simple event");
        bus.post("simple event222");
        logger.info("bus end!");
    }

    @Test
    public void testDeadEvent() {
        EventBus bus = new EventBus("Dead-event-bus") {
            @Override
            public String toString() {
                return "Dead-event-bus";
            }
        };
        bus.register(new DeadEventListener());
        logger.info("bus dead start!");
        bus.post("a dead event");
        logger.info("bus dead end!");
    }
}
